@extends('backend::layout')

@section('title', '班级列表')

@section('content')
    <div class="card border-no">
        <div class="card-body">
            <div class="row">
                <div class="col-md-9 col-sm-9 col-xs-9">
                    <form method="get">
                        <label class="col-md-2 col-sm-12">
                            <select class="form-control" name="year">
                                <option  value="">--请选择学期--</option>
                                @foreach($years as $key => $val)
                                    <option value="{{ $key }}" @if(old('year') == $key || (old('year') === null && (isset($query['year']) && $query['year'] ==  $key )) ) selected @endif >{{ $val }}</option>
                                @endforeach
                            </select>
                        </label>
                        <label class="col-md-2 col-sm-12">
                            <select class="form-control" name="type">
                                <option  value="">--请选择年级--</option>
                                @foreach($types as $key => $val)
                                    <option value="{{ $key }}" @if(old('type') == $key || (old('type') === null && (isset($query['type']) && $query['type'] ==  $key )) ) selected @endif >{{ $val }}</option>
                                @endforeach
                            </select>
                        </label>
                        <label class="col-md-2 col-sm-12">
                            <button class="btn btn-primary btn-sm">查看课表</button>
                        </label>
                    </form>
                </div>
{{--                @if($currentAdmin->allow('classLessonTeacher/add') && !empty($lessons))--}}
{{--                <div class="col-md-3 col-sm-3 col-xs-3">--}}
{{--                    <p class=" pull-right">--}}
{{--                        <a href="{{ route('admin.classLessonTeacher.add') }}" class="btn btn-primary btn-sm">新增课表</a>--}}
{{--                    </p>--}}
{{--                </div>--}}
{{--                @endif--}}
            </div>
            <h4 class="text-black f-20"> </h4>
            <div class="table-responsive">
            @if(!empty($lessons))
                @foreach($lessons as $week=>$item)
                <div style="
                    text-align: center;
                    margin: 20px 0 10px;
                    font-size: 16px;
                    font-weight: bold;
                    color: #ff5b19;
                ">{{ $weeks[$week] }}</div>
                <table class="table">
                    <thead>
                    <tr>
                        <th scope="col">班级</th>
                        <th scope="col">早习</th>
                        <th scope="col">第1节</th>
                        <th scope="col">第2节</th>
                        <th scope="col">第3节</th>
                        <th scope="col">第4节</th>
                        <th scope="col">第5节</th>
                        <th scope="col">第6节</th>
                        <th scope="col">第7节</th>
                        <th scope="col">第8节</th>
                        <th scope="col">晚修1</th>
                        <th scope="col">晚修2</th>
                        <th scope="col">晚修3</th>
                    </tr>
                    </thead>
                    <tbody>
                        @foreach($item as $class=>$lesson)
                            <tr data-class="{{$class}}" data-week="{{$week}}">
                                <td>{{ $class }}班</td>
                                @foreach($lesson as $key=>$val)
                                    <td data-sort="{{$key}}">
                                        @if(empty($val['lesson']) && empty($val['lesson']))
                                            <p class="fa fa-plus-square-o"></p>
                                        @else
                                            <p style="font-weight: bold;color:#000">{{ $val['lesson'] }}</p>
                                            <p>{{ $val['teacher'] }}</p>
                                            <p class="edit fa fa-edit"></p>
                                        @endif
                                    </td>
                                @endforeach
                            </tr>
                        @endforeach
                    </tbody>
                </table>
                @endforeach
            @endif
            </div>
        </div>
    </div>
    <style>
        p {margin: 0}
        th,td {text-align: center;border: 1px solid #eeeeee;vertical-align:middle !important;position: relative}
        td:hover {background: #f4f4f4;cursor: pointer}
        .edit {position: absolute;right:10px;bottom:10px}
    </style>
    <script>
        @if(!empty($query['year']))
        $("td").click(function(){
            let sort = $(this).attr('data-sort')
            let classes = $(this).parent('tr').attr('data-class')
            let weeks = $(this).parent('tr').attr('data-week')
            let years = '{{$query['year']}}'
            window.location.href='{{ route('admin.classLessonTeacher.add') }}?year='+years+'&week='+weeks+'&class='+classes+'&sort='+sort
        });
        @endif
    </script>
@stop